package retrofitdemo.com.night.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.lzy.okgo.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;
import retrofitdemo.com.night.R;
import retrofitdemo.com.night.adapter.FloorAdapter;
import retrofitdemo.com.night.bean.FloorBean;
import retrofitdemo.com.night.databinding.ActivityFloorDescBinding;
import retrofitdemo.com.night.utils.GsonUtil;
import retrofitdemo.com.night.utils.HTTPAPI;
import retrofitdemo.com.night.utils.LogUtil;
import retrofitdemo.com.night.utils.OnItemClickListener;

public class FloorDescActivity extends BaseActivity {

    ActivityFloorDescBinding binding;
    List<FloorBean.DataBean> list = new ArrayList<>();
    List<FloorBean.DataBean> listSecond = new ArrayList<>();
    FloorAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        binding = DataBindingUtil.setContentView( this, R.layout.activity_floor_desc );
        binding.setActivity( this );
        initView();
    }

    private void initView() {
        setLeftVis();
        setTitleText( "楼层" );
        binding.rlModule.setLayoutManager( new LinearLayoutManager( this ) );
        binding.rlModule.setItemAnimator( new DefaultItemAnimator() );
        adapter = new FloorAdapter( this, listSecond );
        binding.rlModule.setAdapter( adapter );
        adapter.setOnItemClickLitener( new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent( FloorDescActivity.this, FloorMoreImageActivity.class );
                intent.putExtra( "module_floorId", listSecond.get( position ).getId() + "" );
                intent.putExtra( "module_floor_name", listSecond.get( position ).getTitle() );
                startActivity( intent );
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        } );

        //获取楼层
        HTTPAPI.getInstance().getBWGFloors( new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                LogUtil.e( "获取楼层成功-->" + s );
                try {
                    FloorBean bean = GsonUtil.GsonToBean( s, FloorBean.class );
                    list.clear();
                    for (FloorBean.DataBean dataBean : bean.getData()) {
                        list.add( dataBean );
                    }
                    listSecond.addAll( list );
                    adapter.notifyDataSetChanged();

                } catch (Exception e) {

                }

            }
        } );
    }
}
